package durose.durose;

import java.util.List;

import durose.system.pojo.DuRose;
import durose.util.DuroseCharFilterUtil;

public class DuRoseJavaControllerGenerator {
	
	
	
	public static String initForeginTablePack(List<DuRose> duroses){
		StringBuffer sb = new StringBuffer();
		for(DuRose durose:duroses){
			if(durose.getColumnRelaTable()!=null&&durose.getColumnRelaTable()!=""){
				sb.append(initForeginTablePack(durose)+"\n");
			}
		}
		return sb.toString();
	}
	
	public static String initForeginTableService(List<DuRose> duroses){
		StringBuffer sb = new StringBuffer();
		for(DuRose durose:duroses){
			if(durose.getColumnRelaTable()!=null&&durose.getColumnRelaTable()!=""){
				sb.append(initForeginTableService(durose)+"\n");
			}
		}
		return sb.toString();
	}
	
	public static String initForeginTableEdit(List<DuRose> duroses){
		StringBuffer sb = new StringBuffer();
		for(DuRose durose:duroses){
			if(durose.getColumnRelaTable()!=null&&durose.getColumnRelaTable()!=""){
				sb.append(initForeginTableEdit(durose)+"\n");
			}
		}
		return sb.toString();
	}
	
	
	
	
	

	public static String initForeginTablePack(DuRose durose){
		String str = "import durose.system.pojo.$ClassName$;\n import durose.system.service.$ClassName$Service; \n";
		str = str.replace("$ClassName$", DuroseCharFilterUtil.toUpperFristChar(durose.getColumnRelaTable()));
		return str;		
	}
	public static String initForeginTableService(DuRose durose){
		String str = "@Autowired \n \t $ClassName$Service $tableName$Service;";
		str = str.replace("$ClassName$", DuroseCharFilterUtil.toUpperFristChar(durose.getColumnRelaTable()));
		str = str.replace("$tableName$", durose.getColumnRelaTable());
		return str;
		
	}
	public static String initForeginTableEdit(DuRose durose){
		String str = "model.addAttribute(\"$tableName$s\", $tableName$Service.$tableName$List(\"\"));";
		str = str.replace("$tableName$", durose.getColumnRelaTable());
		return str;
	}
}
